package com.example.service.impl;

import ch.qos.logback.classic.Logger;
import com.example.entity.*;
import com.example.entity.authority.Party;
import com.example.entity.authority.SystemUser;
import com.example.ext.entity.ExtElevator;
import com.example.ext.entity.ExtSysUser;
import com.example.mapp.*;
import com.example.service.ElevatorService;
import com.example.service.StatisticsService;
import com.example.service.SysUserService;
import com.example.util.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by youkun on 2017/10/5.
 * 电梯信息
 */
@Service
public class ElevatorServiceImpl implements ElevatorService{

    private final static Logger logger = (Logger) LoggerFactory.getLogger(ElevatorServiceImpl.class);

    @Autowired
    private ElevatorMapp elevatorMapp;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private ElevatorTypeMapp elevatorTypeMapp;

    @Autowired
    private PartyMapp partyMapp;

    @Autowired
    private SysUserMapp sysUserMapp;

    @Autowired
    private PromotionMapp promotionMapp;

    @Autowired
    private ImportRecordMapp importRecordMapp;

    @Autowired
    private PointFlowMapp pointFlowMapp;

    @Autowired
    private StatisticsService statisticsServiceImp;

    @Autowired
    private ElevatorLoseMapp elevatorLoseMapp;

    @Autowired
    private TractionMapp tractionMapp;

    @Autowired
    PaperlessMaintMapp paperlessMaintMapp;

    @Override
    public Map<String, Object> queryList(ExtElevator elevator) {
        List<ExtElevator> list =null;
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            List<ExtElevator> extElevators = elevatorMapp.queryList(elevator);
            map.put("listAll",extElevators);
            Page<ExtElevator> page = PageHelper.startPage(elevator.getCurrentPage(), elevator.getPageSize());
            list = elevatorMapp.queryList(elevator);
            map.put("list",list);
            map.put("total",page.getTotal());

        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    /**
     * 查询电梯列表
     **/
    @Override
    public Map<String, Object> queryElevatorList(ExtElevator extElevator) {
        List<ExtElevator> list = null;
        Map<String,Object> map = new HashMap<String,Object>();
        List<Map<String,String>> wuyeList = null;
        List<Map<String,String>> weibaoList = null;
        List<String> listPro = null;
        try {
                Page<ExtElevator> page = PageHelper.startPage(extElevator.getCurrentPage(), extElevator.getPageSize());
                // 查询电梯信息
                list = elevatorMapp.queryElevatorList(extElevator);
                // 查询项目名称
                listPro = elevatorMapp.queryProgramName(extElevator);
                // 查询使用单位
                wuyeList = elevatorMapp.queryUsedParty(extElevator);
                // 查询维保单位
                weibaoList = elevatorMapp.queryMainParty(extElevator);
                map.put("list",list);
                map.put("total",page.getTotal());
                map.put("wuyeList",wuyeList);
                map.put("weibaoList",weibaoList);
                map.put("listPro",listPro);
            System.out.println(map);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }





    @Override
    public Map<String, Object> queryMaintList(Map<String, Object> elevator) {
        List<ExtElevator> list =null;
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            List<ExtElevator> extElevators = elevatorMapp.queryMaintList(elevator);
            map.put("listAll",extElevators);
            Page<ExtElevator> page = PageHelper.startPage(Integer.parseInt(elevator.get("currentPage")+""), Integer.parseInt(elevator.get("pageSize")+""));
            list = elevatorMapp.queryMaintList(elevator);
            map.put("list",list);
            map.put("total",page.getTotal());

        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    @Override
    public Map<String, Object> queryJgList(Map<String, Object> elevator) {
        List<ExtElevator> list =null;
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            List<ExtElevator> extElevators = elevatorMapp.queryJgList(elevator);
            map.put("listAll",extElevators);
            Page<ExtElevator> page = PageHelper.startPage(Integer.parseInt(elevator.get("currentPage")+""), Integer.parseInt(elevator.get("pageSize")+""));
            list = elevatorMapp.queryJgList(elevator);
            map.put("list",list);
            map.put("total",page.getTotal());

        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    /**
     * 电梯台账数据传入接口
     * @param map
     * @return
     */

    @Override
    public Map<String, Object> add(Map<String, Object> map) {
        Map<String, Object> resultMap = new HashMap<>();
        String message = "添加成功";
        try {
            if (map == null || map.size() < 1) {
                message = "新增失败，传入参数为空";
                return ResultUtil.returnError(message, resultMap);
            } else {
                List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("elevatorList");
                if (list != null && list.size() > 500) {
                    message = "新增失败，传入参数不能大于500";
                    return ResultUtil.returnError(message, resultMap);
                }
                // 保存到持久表里
                elevatorMapp.interfaceAddPersistent(list);
                // 保存到临时表里
                elevatorMapp.interfaceAddCursor(list);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(), resultMap);
        }
        return ResultUtil.returnSuccess(message, resultMap);
    }

    /**
     *
     * 每天定时修改定时数据
     *
     * @param
     * @return
     */
    public void updateReceiveTableData() {
        try {
            // 查询持久表数据
            List<ReceiveHesuElevator> receiveHesuList = elevatorMapp.receiveHesuElevator();
            if (receiveHesuList != null && receiveHesuList.size() > 0) {
                // 查询数据库里是否存在数据
                for (ReceiveHesuElevator hesuElevator : receiveHesuList) {
                    if (StringUtils.isNotBlank(hesuElevator.getOutElevatorId())) {
                        ReceiveHesuElevator elevator = elevatorMapp.interfaceFindData(hesuElevator.getOutElevatorId());
                        if (elevator != null) {
                            // 电梯类型为空
                            if (elevator.getElevatorTypeId() == null) {
                                hesuElevator = this.updateElevatorType(hesuElevator);
                            }
                            // 修改
                            int i = elevatorMapp.interfaceUpdateByNum(hesuElevator);
                            if (i > 0) {
                                elevatorMapp.deleteReceiveHesuById(hesuElevator.getId());
                            }

                        } else {
                            // 按照注册代码查询是否为空
                            Elevator byElevatorNum = elevatorMapp.
                                    queryByElevatorNum(hesuElevator.getElevatorNum());
                            if (byElevatorNum != null) {
                                continue;
                            }
                            // 修改电梯类型
                            hesuElevator = this.updateElevatorType(hesuElevator);
                            // 新增
                            int i = elevatorMapp.insertIntoAdd(hesuElevator);
                            if (i > 0) {
                                elevatorMapp.deleteReceiveHesuById(hesuElevator.getId());
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }

    // 获取使用单位信息
    public ReceiveHesuElevator getUsedInfo(ReceiveHesuElevator hesuElevator){
        // 步骤一：通过营业执照号码查询
        if (StringUtils.isNotBlank(hesuElevator.getUsedPartyCreditCode())){
            Party party = new Party();
            party.setPartyType("2");
            party.setCreditCode(hesuElevator.getUsedPartyCreditCode());
            Party p = partyMapp.queryByCreditCode(party);
            if (p == null) {
                // 步骤1-2：通过中文名称查询
                party.setPartyName(hesuElevator.getUsedPartyName());
                p = partyMapp.queryByPartyTypeAndName(party);
            }

            if (p != null) {
                // 赋值
                hesuElevator.setUsedPartyId(p.getId());
            }
        }
        return hesuElevator;
    }

    // 获取维保单位信息
    public ReceiveHesuElevator getMaintenanceInfo(ReceiveHesuElevator hesuElevator){
        // 步骤一：通过营业执照号码查询
        if (StringUtils.isNotBlank(hesuElevator.getMaintenancePartyCreditCode())){
            Party party = new Party();
            party.setPartyType("1");
            party.setCreditCode(hesuElevator.getMaintenancePartyCreditCode());
            Party mp = partyMapp.queryByCreditCode(party);
            if (mp == null) {
                // 步骤2-2：通过中文名称查询
                party.setPartyName(hesuElevator.getMaintenancePartyName());
                mp = partyMapp.queryByPartyTypeAndName(party);
            }

            if (mp != null) {
                // 赋值
                hesuElevator.setMaintenancePartyId(mp.getId());
            }
        }
        return hesuElevator;
    }

    // 修改电梯类型
    public ReceiveHesuElevator updateElevatorType(ReceiveHesuElevator hesuElevator) {
        if (StringUtils.isNotBlank(hesuElevator.getElevatorTypeName())) {

            String typeName = hesuElevator.getElevatorTypeName();
            if ("曳引驱动乘客电梯".equals(typeName)
                    || "消防员电梯".equals(typeName)
                    || "曳引式客梯".equals(typeName)) {
                hesuElevator.setElevatorTypeId(1);
            }

            if ("曳引驱动载货电梯".equals(typeName) || "强制驱动载货电梯".equals(typeName)
                    || "曳引式货梯".equals(typeName)) {
                hesuElevator.setElevatorTypeId(5);
            }
            if ("自动扶梯".equals(typeName)) {
                hesuElevator.setElevatorTypeId(4);
            }
            if ("自动人行道".equals(typeName)) {
                hesuElevator.setElevatorTypeId(6);
            }
            if ("杂物电梯".equals(typeName)) {
                hesuElevator.setElevatorTypeId(3);
            }
            if ("液压载货电梯".equals(typeName) || "液压乘客电梯".equals(typeName)) {
                hesuElevator.setElevatorTypeId(2);
            }
        }
        return hesuElevator;
    }



    @Override
    public Map<String, Object> update(Elevator elevator) {
        Elevator updateBefore = null;
        try {
            //查询数据是否存在
            Elevator system = elevatorMapp.queryById(elevator.getId().toString());
            if(null==system){
                throw new Exception("数据不存在!");
            }
//            updateBefore = system;

            if(elevator.getElevatorNum().equals(system.getElevatorNum())){
                elevatorMapp.update(elevator);
            }else{
                Elevator sys = elevatorMapp.queryByElevatorNum(elevator.getElevatorNum());
                if(null==sys){
                    elevator.setQrCodeUrl(system.getQrCodeUrl());
                    elevatorMapp.update(elevator);
                }else {
                    throw new Exception(elevator.getElevatorNum()+"已存在!");
                }
            }
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }finally {
            if ("2".equals(elevator.getLoggerType()) && "16".equals(elevator.getRoleId())) {
                // 电梯修改，回影响占比
                PointDefendInfoCache infoCache = new PointDefendInfoCache();
                PointDefend pointDefend = infoCache.getKeyByValue("add_elevator_info");

                if (pointDefend != null) {
                    // 获取必填字段
                    List<String> strings = Arrays.asList(pointDefend.getMustBean().split(","));
                    double rate = ObjectBeanUtils.percentage(elevator, strings);
                    if (rate != 0) {
                        // 单个电梯的积分
                        int round = (int) (rate * pointDefend.getMark());
                        // 当照片进行更新后，加10分
                        String message = "";

                        // 先将单个电梯的积分清空，然后再将新的积分更新
                        elevator.setMark(round);
                        elevatorMapp.updateMark(elevator);
                        // 计算单位下所有的电梯积分，得到单位总积分
                        Map sumMark = elevatorMapp.getSumMark(elevator.getUsedPartyId().toString());
                        int allElevator = Integer.parseInt(sumMark.get("mark")+"");
                        // 查询角色信息得到单位总积分
                        Map<String, Object> maps = pointFlowMapp.findUserInfo(elevator.getUsedPartyId());
                        long mark = (long) maps.get("mark");

                        // 查询流水表里是否有记录了，如果有删除掉，再加
                        PointFlow pointFlow = new PointFlow();
                        pointFlow.setIdentification("add_elevator_info");
                        List<PointFlow> flowlist = pointFlowMapp.findOne(pointFlow);
                        if (flowlist != null && flowlist.size() > 0) {
                            round = (int) ((mark - flowlist.get(0).getMark()) + allElevator);
                        } else {
                            round = (int) (mark + allElevator);
                        }
                        // 更新单位总积分
                        String userId = (String) maps.get("userId");
                        int i1 = pointFlowMapp.updateMark(round, userId);
                        // 插入流水
                        String userName = (String) maps.get("userName");
                        String partyName = (String) maps.get("partyName");
                        String function = "修改电梯" + message;
                        SystemPointUtil.insertFlow(pointFlowMapp, i1, pointDefend, allElevator, userName, partyName, function);

                        // 添加安全管理员的积分
                        PointDefend pointUserDefend = infoCache.getKeyByValue("add_elevator_info_user");
                        Map<String, Object> usermaps = pointFlowMapp.findUserInfoByUserId(Long.valueOf(elevator.getLoggerUserId()));

                        // 计算分数
                        int roundUsers = (int) (rate * pointUserDefend.getMark());

                        // 判断原来的分数是否为 0
                        long markUsers = (long) usermaps.get("mark");
                        if(markUsers != 0){
                            // 通过唯一标识查询流水表获取上一次积分，然后减去
                            PointFlow pointUserFlow = new PointFlow();
                            pointUserFlow.setIdentification("add_elevator_info_user");
                            List<PointFlow> list = pointFlowMapp.findOne(pointUserFlow);
                            if (list != null && list.size() > 0) {
                                roundUsers = (int) ((markUsers - list.get(0).getMark()) + roundUsers);
                            } else {
                                roundUsers = (int) (markUsers + roundUsers);
                            }
                        }
                        int i2 = pointFlowMapp.updateMark(roundUsers, elevator.getLoggerUserId());
                        String userName2 = "电梯安全管理员";
                        String partyName2 = (String) maps.get("partyName");
                        SystemPointUtil.insertFlow(pointFlowMapp,i2,pointUserDefend,roundUsers,userName2,partyName2,"建立电梯台账、录入电梯使用登记信息");
                    }
                }
            }
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    @Override
    public Map<String, Object> updatehmMaintDate(Map<String,Object> inMap) {
        try {
            String date = (new SimpleDateFormat("yyyyMMdd")).format(new Date());
            inMap.put("lastMaintenanceTime",date);
            /**
             * 判断是否参数按需维保，获取维保天数
             */
            ExtElevator elevator = new ExtElevator();
            elevator.setElevatorNum(inMap.get("elevatorNum")+"");
            List<ExtElevator> extElevators = elevatorMapp.queryList(elevator);

            int addDay = 15;
            if (extElevators != null && extElevators.size() != 0) {
                String isParticipateIn = extElevators.get(0).getIsParticipateIn();
                //参加了无纸化
                if (StringUtils.isNotBlank(isParticipateIn) && "1".equals(isParticipateIn)) {
                    addDay = extElevators.get(0).getMaintenanceDay();
                }
            }
            Calendar calendar2 = Calendar.getInstance();
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");

            calendar2.add(Calendar.DATE, addDay);
            String dd= sdf2.format(calendar2.getTime());
            inMap.put("nextHalfmonMaintDate",dd);

            elevatorMapp.updatehmMaintDate(inMap);

        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    @Override
    public Map<String, Object> updateqMaintDate(Map<String,Object> inMap) {
        try {
            String date = (new SimpleDateFormat("yyyyMMdd")).format(new Date());
            inMap.put("lastMaintenanceTime",date);

            Calendar calendar2 = Calendar.getInstance();
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
            calendar2.add(Calendar.DATE, 90);
            String dd= sdf2.format(calendar2.getTime());
            inMap.put("nextQuarterlyMainteDate",dd);

            elevatorMapp.updateqMaintDate(inMap);

        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    @Override
    public Map<String, Object> updatehyMaintDate(Map<String,Object> inMap) {
        try {
            String date = (new SimpleDateFormat("yyyyMMdd")).format(new Date());
            inMap.put("lastMaintenanceTime",date);

            Calendar calendar2 = Calendar.getInstance();
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
            calendar2.add(Calendar.DATE, 180);
            String dd= sdf2.format(calendar2.getTime());
            inMap.put("nextHalfyearMaintDate",dd);

            elevatorMapp.updatehyMaintDate(inMap);

        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    @Override
    public Map<String, Object> updateyMaintDate(Map<String,Object> inMap) {
        try {
            String date = (new SimpleDateFormat("yyyyMMdd")).format(new Date());
            inMap.put("lastMaintenanceTime",date);

            Calendar calendar2 = Calendar.getInstance();
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
            calendar2.add(Calendar.DATE, 360);
            String dd= sdf2.format(calendar2.getTime());
            inMap.put("nextYearMaintDate",dd);

            elevatorMapp.updateyMaintDate(inMap);

        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    public Map<String, Object> updateLatLng(Map<String,Object> inMap){
        try {

            elevatorMapp.updateLatLng(inMap);

        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    /**
     * 电梯台账导入电梯列表
     * @param file
     * @param partyId
     * @return
     */
    @Override
    @Transactional
    public Map<String, Object> importElevator(MultipartFile file, String partyId) {

        Map<String,Object> resultmap = new HashMap<>();
        try {
            List<List<Object>> list = ExcelUtil.getListByExcel(file.getInputStream(),file.getOriginalFilename());
            //获取导入的信息做处理
            if(list!=null && list.size()>0){
                // 获取电梯类型
                Map<String, Long> typemap = new HashMap<>();
                List<ElevatorType> types = elevatorTypeMapp.queryList();
                if (types != null) {
                    for (ElevatorType elevatorType : types) {
                        typemap.put(elevatorType.getTypeName(), elevatorType.getId());
                    }
                } else {
                    ResultUtil.returnSuccess("数据库里电梯类型为空", null);
                }
                // 获取本单位下得安全管理员
                Map<String,Long> safeUserMap = new HashMap<>();
                List<SystemUser> users = sysUserMapp.queryMainByPartyId(partyId);
                if (users != null) {
                    for (SystemUser user : users) {
                        safeUserMap.put(user.getUserName(), user.getId());
                    }
                } else {
                    ResultUtil.returnSuccess("本单位下电梯安全管理员为空，请先注册电梯安全管理员", null);
                }
                // 获取维保单位账号
                Map<String,Long> partymap = new HashMap<>();
                String partyType="1";
                List<Party> partyList = partyMapp.queryByTypeList(partyType);
                for (Party party : partyList) {
                    partymap.put(party.getPartyName(), party.getId());
                }

                // 查询所属分局
                Map<String, Long> branchOfficeMap = new HashMap<>();
                String ptype = "4";
                List<Party> branchOfficeList = partyMapp.queryByTypeList(ptype);
                for (Party party : branchOfficeList) {
                    branchOfficeMap.put(party.getPartyName(), party.getId());
                }

                // 已经存在库里的电梯
                List<String> alist = new ArrayList<>();


                for (int i = 0; i < list.size(); i++) {
                    List listObject = list.get(i);
                    if(listObject!=null){
                        Elevator elevator = new Elevator();
                        //物业id
                        elevator.setUsedPartyId(Long.parseLong(partyId));

                        //安装地点
                        if (listObject.get(1) != null && StringUtils.isNotBlank(
                                listObject.get(1).toString().trim())) {
                            elevator.setBuildAddr(listObject.get(1).toString().trim());
                        }
                        // 设备类型
                        if (listObject.get(2) != null && StringUtils.isNotBlank(
                                listObject.get(2).toString().trim())) {
                            Long typeId = typemap.get(listObject.get(2).toString().trim());
                            if (typeId == null) {
                                throw new Exception("设备类型:'" + listObject.get(2).toString() + "'不存在");
                            }
                            elevator.setElevatorTypeId(typeId);
                        } else {
                            throw new Exception("序号为：" + listObject.get(0) + " 的设备类型不能为空!");
                        }
                        // 设备型号
                        if (listObject.get(3) != null && StringUtils.isNotBlank(
                                listObject.get(3).toString().trim())) {
                            elevator.setElevatorModel(listObject.get(3).toString().trim());
                        }
                        // 注册代码,如果注册代码为空，不处理
                        if (listObject.get(4) != null && StringUtils.isNotBlank(
                                listObject.get(4).toString().trim())) {
                            Elevator sys = elevatorMapp.queryByElevatorNum(listObject.get(4).toString().trim());
                            if (sys != null) {
                                alist.add(listObject.get(0).toString().trim());
                                continue;
                            } else {
                                elevator.setElevatorNum(listObject.get(4).toString().trim());
                            }
                        } else {
                            throw new Exception("序号为：" + listObject.get(0) + " 的设备注册代码不能为空！");
                        }
                        // 使用证号,
                        if (listObject.get(5) != null && StringUtils.isNotBlank(
                                listObject.get(5).toString().trim())) {
                            elevator.setUsedNum(listObject.get(5).toString().trim());
                        }
                        // 投用日期,
                        if (listObject.get(6) != null && StringUtils.isNotBlank(
                                listObject.get(6).toString().trim())) {

                            if ((listObject.get(6).toString()).contains("-")) {
                                elevator.setBeUsedDate(listObject.get(6).toString()
                                        .replaceAll("-", "").trim());
                            } else {
                                elevator.setBeUsedDate(listObject.get(6).toString()
                                        .split("\\.")[0]);
                            }
                        }
                        // 年检日期,
                        if (listObject.get(7) != null && StringUtils.isNotBlank(
                                listObject.get(7).toString().trim())) {

                            if ((listObject.get(7).toString()).contains("-")) {
                                elevator.setNextCheckDate(listObject.get(7).toString()
                                        .replaceAll("-", "").trim());
                            } else {
                                elevator.setNextCheckDate(listObject.get(7).toString()
                                        .split("\\.")[0]);
                            }
                        }
                        // 限速器检验日期
                        if (listObject.get(8) != null && StringUtils.isNotBlank(
                                listObject.get(8).toString().trim())) {

                            if ((listObject.get(8).toString()).contains("-")) {
                                elevator.setGovernorCkDate(listObject.get(8).toString()
                                        .replaceAll("-", "").trim());
                            } else {
                                elevator.setGovernorCkDate(listObject.get(8).toString()
                                        .split("\\.")[0]);
                            }
                        }
                        // 层/站
                        if (listObject.get(9) != null &&
                                StringUtils.isNotBlank(listObject.get(9).toString().trim())) {
                            elevator.setFloorStation(listObject.get(9).toString().trim());
                        }
                        // 使用状况
                        if (listObject.get(10) != null && StringUtils.isNotBlank(
                                listObject.get(10).toString().trim())) {
                            //0在用  1停用 2安装 3注销
                            if (listObject.get(10).toString().equals("在用")) {
                                elevator.setIsStop("0");
                            } else if (listObject.get(10).toString().equals("停用")) {
                                elevator.setIsStop("1");
                            } else if (listObject.get(10).toString().equals("安装")) {
                                elevator.setIsStop("2");
                            } else if (listObject.get(10).toString().equals("注销")) {
                                elevator.setIsStop("3");
                            } else {
                                throw new Exception("使用状况有：在用，停用，安装，注销请填写正确");
                            }
                        }
                        // 安全管理员
                        if (listObject.get(11) != null && StringUtils.isNotBlank(
                                listObject.get(11).toString().trim())) {

                            Long safeUserId = safeUserMap.get(listObject.get(11).toString().trim());
                            if (safeUserId != null) {
                                elevator.setSafeUserId(safeUserId);
                            } else {
                                throw new Exception("序号为：" + listObject.get(0)
                                        + " 的安全管理员未注册，请先注册该安全管理员！");
                            }
                        }
                        // 联系电话,
                        if (listObject.get(12) != null && StringUtils.isNotBlank(
                                listObject.get(12).toString().trim())) {
                            elevator.setSafeUserTel(listObject.get(12).toString());
                        }
                        // 维保单位
                        if(listObject.get(13)!=null && StringUtils.isNotBlank(
                                listObject.get(13).toString().trim()) ){

                            Long maintanceId = partymap.get(listObject.get(13).toString().trim());
                            if (maintanceId != null) {
                                elevator.setMaintenancePartyId(maintanceId);
                            }
                        }
                        // 维保人员
                        if (listObject.get(14) != null && StringUtils.isNotBlank(
                                listObject.get(14).toString().trim())) {

                            String maintenanceUser = listObject.get(14).toString().trim();
                            List<String> userList =Arrays.asList(maintenanceUser.split(","));
                            ExtSysUser extSysUser = new ExtSysUser();

                            extSysUser.setPartyId(elevator.getMaintenancePartyId());
                            if (StringUtils.isNotBlank(userList.get(0))) {
                                extSysUser.setUserName(userList.get(0));
                                List<ExtSysUser> systemUserList = sysUserMapp.
                                        findUserByPartyIdAndUserName(extSysUser);
                                if (systemUserList != null && systemUserList.size() > 0) {
                                    elevator.setMaintenanceUserFirst(systemUserList.get(0).getId());
                                }
                            }

                            if (userList != null && userList.size() > 1) {
                                extSysUser.setUserName(userList.get(1));
                                List<ExtSysUser> systemUserList = sysUserMapp.
                                        findUserByPartyIdAndUserName(extSysUser);
                                if (systemUserList != null && systemUserList.size() > 0) {
                                    elevator.setMaintenanceUserSecond(systemUserList.get(0).getId());
                                }
                            }


                        }

                        //联系电话
                        if (listObject.get(15) != null) {
                            elevator.setMaintTel(listObject.get(15).toString().trim());
                        }
                        // 额定载荷,
                        if (listObject.get(16) != null) {
                            elevator.setRatedLoad(listObject.get(16).toString().trim());
                        }
                        // 运行速度,
                        if (listObject.get(17) != null) {
                            elevator.setRunSpeed(listObject.get(17).toString().trim());
                        }
                        // 出厂编号,
                        if (listObject.get(18) != null) {
                            elevator.setSerialNum(listObject.get(18).toString().trim());
                        }
                        // 制造单位,
                        if (listObject.get(19) != null) {
                            elevator.setCreateCompanyName(listObject.get(19).toString().trim());
                        }
                        // 安装单位,
                        if (listObject.get(20) != null) {
                            elevator.setBuildPartyName(listObject.get(20).toString().trim());
                        }
                        // 电梯安全责任保险投保单位名称,
                        if (listObject.get(21) != null) {
                            elevator.setInsuranceName(listObject.get(21).toString().trim());
                        }
                        // 电梯安全责任保险到期日期,
                        if (listObject.get(22) != null && StringUtils.isNotBlank(
                                listObject.get(22).toString().trim())) {

                            if ((listObject.get(22) + "").contains("-")) {
                                elevator.setInsuranceDate(listObject.get(22).toString().replaceAll("-", "").trim());
                            } else {
                                elevator.setInsuranceDate(listObject.get(22).toString().split("\\.")[0]);
                            }
                        }
                        // 载重/角度,
                        if (listObject.get(23) != null) {
                            elevator.setAngle(listObject.get(23).toString().trim());
                        }
                        // 梯级宽度,
                        if (listObject.get(24) != null) {
                            elevator.setStepWidth(listObject.get(24).toString().trim());
                        }
                        // 提升高度,
                        if (listObject.get(25) != null) {
                            elevator.setLiftHeight(listObject.get(25).toString().trim());
                        }
                        //上次维保时间
                        if (listObject.get(26) != null && StringUtils.isNotBlank(
                                listObject.get(26).toString().trim())) {

                            if ((listObject.get(26) + "").contains("-")) {
                                elevator.setLastMaintenanceTime(listObject.get(26).toString().replaceAll("-", "").trim());
                            } else {
                                elevator.setLastMaintenanceTime(listObject.get(26).toString().split("\\.")[0]);
                            }
                        }
                        // 下次半月保时间,
                        if (listObject.get(27) != null && StringUtils.isNotBlank(
                                listObject.get(27).toString().trim())) {

                            if ((listObject.get(27) + "").contains("-")) {
                                elevator.setNextHalfmonMaintDate(listObject.get(27).toString().replaceAll("-", "").trim());
                            } else {
                                elevator.setNextHalfmonMaintDate(listObject.get(27).toString().split("\\.")[0]);
                            }
                        }
                        // 下次季度保时间,
                        if (listObject.get(28) != null && StringUtils.isNotBlank(
                                listObject.get(28).toString().trim())) {

                            if ((listObject.get(28) + "").contains("-")) {
                                elevator.setNextQuarterlyMainteDate(listObject.get(28).toString().replaceAll("-", "").trim());
                            } else {
                                elevator.setNextQuarterlyMainteDate(listObject.get(28).toString().split("\\.")[0]);
                            }
                        }
                        // 下次半年保时间,
                        if (listObject.get(29) != null && !"".equals(listObject.get(29) + "")) {
                            if ((listObject.get(29) + "").contains("-")) {
                                elevator.setNextHalfyearMaintDate(listObject.get(29).toString().replaceAll("-", "").trim());
                            } else {
                                elevator.setNextHalfyearMaintDate(listObject.get(29).toString().split("\\.")[0]);
                            }
                        }
                        // 下次年保时间,
                        if (listObject.get(30) != null && !"".equals(listObject.get(30) + "")) {
                            if ((listObject.get(30) + "").contains("-")) {
                                elevator.setBeUsedDate(listObject.get(30).toString().replaceAll("-", "").trim());
                            } else {
                                elevator.setBeUsedDate(listObject.get(30).toString().split("\\.")[0]);
                            }
                        }
                        // 救援电话
                        if (listObject.get(31) != null) {
                            elevator.setRescuePhoneNum(listObject.get(31).toString().trim());
                        }
                        // 外部关联码
                        if (listObject.get(32) != null) {
                            elevator.setOutsideNum(listObject.get(32).toString().trim());
                        }

                        //后来添加的电梯品牌添加到最后
                        if (listObject.get(33) != null) {
                            elevator.setBrandName(listObject.get(33).toString().trim());
                        }
                        if(listObject.get(34) != null){ //检验人员1 （暂时没有检验模块）

                        }
                        if(listObject.get(35) != null){ //检验人员2

                        }
                        if (listObject.get(36) != null) {//内部编号
                            elevator.setInnerId(listObject.get(36).toString().trim());
                        }
                        if (listObject.get(37) != null) {//上次巡检时间
                            if ((listObject.get(37) + "").contains("-")) {
                                elevator.setBeUsedDate(listObject.get(37).toString().replaceAll("-", "").trim());
                            } else {
                                elevator.setBeUsedDate(listObject.get(37).toString().split("\\.")[0]);
                            }
                        }
                        if(listObject.get(38) != null){//项目名称
                            elevator.setProgramName(listObject.get(38).toString().trim());
                        }
                        if (listObject.get(39) != null) {//所属分局
                            Long officeId = branchOfficeMap.get(listObject.get(39).toString().trim());
                            if (officeId != null) {
                                elevator.setBranchOffice(String.valueOf(officeId));
                            }
                        }
                        if (listObject.get(40) != null) {//场所类型
                            elevator.setPlaceType(listObject.get(40).toString().trim());
                        }
                        if (listObject.get(41) != null) {//场所名称
                            elevator.setElevatorPlace(listObject.get(41).toString().trim());
                        }
                        if (listObject.get(42) != null) {//检验单位名称
                            elevator.setExaminationPartyName(listObject.get(42).toString().trim());
                        }
                        if (listObject.get(43) != null) {//电梯驱动方式
                            elevator.setDriveWay(listObject.get(43).toString().trim());
                        }

                        //插入电梯
                        elevator.setPointsNum("0");
                        elevatorMapp.add(elevator);
                        Map<String,Object> map =  sysUserService.createQrcode(elevator.getId().toString(),elevator.getElevatorTypeId().toString(), elevator.getElevatorNum(),partyId);
                        if(map.get("status").toString().equals("200")){
                            elevator.setQrCodeUrl(((Map)map.get("data")).get("imagePath")+"");
                            elevator.setUrl(((Map)map.get("data")).get("urlPath")+"");
                        }
                        //更新
                        elevatorMapp.update(elevator);

                        /*   // 电梯批量操作后，进行积分计算
                        // 获取缓存数据
                        PointDefendInfoCache infoCache = new PointDefendInfoCache();
                        PointDefend pointDefend = infoCache.getKeyByValue("add_elevator_info");
                        if (pointDefend != null) {
                            // 获取必填字段
                            List<String> strings = Arrays.asList(pointDefend.getMustBean().split(","));
                            double rate = ObjectBeanUtils.percentage(elevator, strings);
                            if (rate != 0) {
                                // 单个电梯的积分
                                int round = (int) (rate * pointDefend.getMark());
                                // 先将单个电梯的积分清空，然后再将新的积分更新
                                elevator.setMark(round);
                                elevatorMapp.updateMark(elevator);
                                // 计算单位下所有的电梯积分，得到单位总积分
                                Map sumMark = elevatorMapp.getSumMark(partyId);
                                int allElevator = Integer.parseInt(sumMark.get("mark")+"");
                                // 查询角色信息得到单位总积分
                                Map<String, Object> maps = pointFlowMapp.findUserInfo(Long.valueOf(partyId));
                                long mark = (long) maps.get("mark");

                                // 查询流水表里是否有记录了，如果有删除掉，再加
                                PointFlow pointFlow = new PointFlow();
                                pointFlow.setIdentification("add_elevator_info");
                                List<PointFlow> flowlist = pointFlowMapp.findList(pointFlow);
                                if (flowlist != null && flowlist.size() > 0) {
                                    round = (int) ((mark - flowlist.get(0).getMark()) + allElevator);
                                }else{
                                    round = (int) (mark + allElevator);
                                }
                                // 更新单位总积分
                                String userId = (String) maps.get("userId");
                                int i1 = pointFlowMapp.updateMark(round, userId);
                                // 插入流水
                                String userName = (String) maps.get("userName");
                                String partyName = (String) maps.get("partyName");
                                String function = "新增电梯";
                                SystemPointUtil.insertFlow(pointFlowMapp, i1, pointDefend, allElevator, userName, partyName, function);

                            }
                        }*/
                    }
                }
                if (alist != null && alist.size() > 0) {
                    resultmap.put("data", "序号为：" + String.join(",", alist) + "行的电梯已经存在库里，暂不做导入操作");
                }
            }
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error("上传电梯失败："+e.getMessage(),e);
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",resultmap);
    }


    @Override
    @Transactional
    public Map<String, Object> delete(List<String> ids) {
        try {
            PointDefendInfoCache infoCache = new PointDefendInfoCache();
            PointDefend pointDefend = infoCache.getKeyByValue("add_elevator_info");
            for(int i=0;i<ids.size();i++){

                // 先获取单位Id
                ExtElevator extElevator = elevatorMapp.queryById(ids.get(i));
                elevatorMapp.deleteById(ids.get(i));

                // 查询角色信息得到单位总积分
                Map<String, Object> maps = pointFlowMapp.findUserInfo(extElevator.getUsedPartyId());
                long mark = (long) maps.get("mark");

                int round = (int) (mark - pointDefend.getMark());

                // 更新单位总积分
                String userId = (String) maps.get("userId");
                int i1 = pointFlowMapp.updateMark(round, userId);

                // 插入流水
                String userName = (String) maps.get("userName");
                String partyName = (String) maps.get("partyName");
                String function = "删除电梯";
                SystemPointUtil.insertFlow(pointFlowMapp, i1, pointDefend, round, userName, partyName, function);

            }
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error(e.getMessage());
            return ResultUtil.returnError("失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }
    /**
     * 批量删除电梯
     * @param ids
     * @return
     */
    @Override
    @Transactional
    public Map<String,Object> batchDelete(List<String> ids){
        try {
            for(int i=0;i<ids.size();i++){
                elevatorMapp.batchDelete(ids.get(i));
            }
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error(e.getMessage());
            return ResultUtil.returnError("失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    @Override
    public Map<String, Object> queryById(String id) {
        ExtElevator elevator = null;
        try {
            elevator = elevatorMapp.queryById(id);
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",elevator);
    }

    @Override
    public Map<String, Object> getLatLng(Map<String,Object> inMap){
        String partyId = Integer.toString((Integer) inMap.get("partyId"));
        List<Map> elevator = null;
        try {
            String mark = statisticsServiceImp.decideInfo(partyId);
            elevator = elevatorMapp.getLatLng(inMap,mark);
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",elevator);

    }

    @Override
    public Map<String, Object> updateElevatorPlace(Map<String, Object> inMap) {
        try {
            elevatorMapp.updateElevatorPlace(inMap);
        }catch (Exception e){
            logger.error(e.getMessage(),e);
            return ResultUtil.returnError("更新失败",null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    @Override
    public Map<String, Object> updateSafeUser(Map<String, Object> inMap) {
        try {
            elevatorMapp.updateSafeUser(inMap);
        }catch (Exception e){
            logger.error(e.getMessage(),e);
            return ResultUtil.returnError("更新失败",null);
        }
        return ResultUtil.returnSuccess("成功",null);
    }

    @Override
    public Map<String,Object> getElevatorInfoByNum(Map<String, Object> param) {
        ExtElevator elevator = null;
        try {
            elevator = elevatorMapp.getElevatorInfoByNum(param);
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",elevator);
    }

    /**
     * 双随机一公开查询电梯信息
     * @param param
     * @return
     */
    @Override
    public Map<String, Object> getElevatorList(Map<String, Object> param) {
        String message = "查询成功";
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            // 获取过滤后的参数
            Map<String, Object> filterParam = param;

            int currentPage = (int) param.get("currentPage");
            int pageSize = (int) param.get("pageSize");
            if (StringUtil.isNotBlank(currentPage+"") && StringUtil.isNotBlank(pageSize+"") ) {
                Page<Map<String,Object>> page = PageHelper.startPage(currentPage, pageSize);

                if (param.get("elevatorPlaceParam") != null) {
                    String elevatorPlaceParam = param.get("elevatorPlaceParam").toString();
                    if (StringUtil.isNotBlank(elevatorPlaceParam)) {
                        List<String> place = Arrays.asList(elevatorPlaceParam.split(","));
                        param.put("elevatorPlaceParam", place);

                        filterParam.put("elevatorPlaceParam", place);
                    }
                }
                List<Map<String, Object>> list = elevatorMapp.getElevatorList(param);
                List<Map<String, Object>> lists = elevatorMapp.getElevatorList(filterParam);
                Map<String, Object> paramList = new HashMap<>();
                if (lists != null && lists.size() > 0) {
                    for (Map<String, Object> objectMap : lists) {
                        String usedPartyId = objectMap.get("usedPartyId").toString();
                        if (paramList.containsKey(usedPartyId)) {
                            continue;
                        } else {
                            paramList.put(usedPartyId, objectMap);
                        }
                    }
                }
                List<Map<String, Object>> unitlist = new ArrayList<>();
                if (paramList != null && paramList.size() > 0) {
                    for (Map.Entry<String, Object> object : paramList.entrySet()) {
                        unitlist.add((Map<String, Object>) object.getValue());
                    }
                }
                map.put("list", list);
                map.put("total", page.getTotal());
                map.put("unitlist",unitlist);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            message = "查询失败";
            return ResultUtil.returnError(message + e.getMessage(), map);
        }
        return ResultUtil.returnSuccess(message, map);
    }

    @Override
    public Map<String, Object> demandMaintGetElevators(ExtElevator elevator) {
        List<ExtElevator> list =null;
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            Page<ExtElevator> page = null;
            if(elevator.getCurrentPage() != null){
                page = PageHelper.startPage(elevator.getCurrentPage(), elevator.getPageSize());
            }

            list = elevatorMapp.demandMaintGetElevators(elevator);

            List<ExtElevator> partyNames = elevatorMapp.getPartyNameById(elevator.getMaintenancePartyId());
            map.put("list",list);
            map.put("listSelect",partyNames);
            if(elevator.getCurrentPage() != null){
                map.put("total",page.getTotal());
            }

        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    /**
     * 获取某区下的电梯列表
     * @param elevator
     * @return
     */
    @Override
    public Map<String, Object> paperlessMaintGetElevators(ExtElevator elevator) {
        List<ExtElevator> list =null;
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            Page<ExtElevator> page = null;
            if(elevator.getCurrentPage() != null){
                page = PageHelper.startPage(elevator.getCurrentPage(), elevator.getPageSize());
            }

            Map<String, Object> map2 = new HashMap<>();
            map2.put("jgPartyId", elevator.getJgPartyId());
            map2.put("maintenancePartyId", elevator.getMaintenancePartyId());

            if (elevator.getElevatorTypeId() != null){
                map2.put("elevatorTypeId", elevator.getElevatorTypeId());
            }

            if (elevator.getElevatorNum() != null) {
                map2.put("elevatorNum", elevator.getElevatorNum());
            }

            if(StringUtil.isNotBlank(elevator.getElevators())){
                map2.put("elevators",elevator.getElevators());
            }


            List<Map<String, Object>> areaElevatorList = paperlessMaintMapp.
                    paperlessGetAreaElevatorList(map2);

            /*list = elevatorMapp.paperlessMaintGetElevators(elevator);*/
            map.put("list",areaElevatorList);
            if(elevator.getCurrentPage() != null){
                map.put("total",page.getTotal());
            }

        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    @Override
    public Map<String, Object> queryCreateCompanys(ExtElevator elevator) {
        List<String> list = null;
        Map<String,Object> map = new HashMap<>();
        try{
            list = elevatorMapp.queryCreateCompanys(elevator);
            map.put("list",list);
        }catch (Exception e){
            logger.error(e.getMessage(),e);
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    @Override
    public Map<String, Object> detectionGetElevator(Map<String, Object> param) {
        List<Map<String, Object>> list =null;
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            Page<ExtElevator> page = null;
            if(param.get("pageSize") != null && !"".equals(param.get("pageSize"))){
                int pageSize = (int) param.get("pageSize");
                int currentPage = (int) param.get("currentPage");
                page = PageHelper.startPage(currentPage, pageSize);
            }

            list = elevatorMapp.detectionGetElevator(param);
            map.put("list",list);
            if(param.get("pageSize") != null && !"".equals(param.get("pageSize"))){
                map.put("total",page.getTotal());
            }

        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    @Override
    public Map<String, Object> updateChessboard(Map<String, Object> param) {

        elevatorMapp.updateChessboard(param);
        return ResultUtil.returnSuccess("成功",param.get("branchOfficeId"));
    }

    /**
     * 修改电梯类型
     * @param param
     * @return
     */
    public Map<String,Object> updateElevatorType(Map<String,Object> param){
        try {
          elevatorMapp.updateElevatorType(param);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return ResultUtil.returnError("修改失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("修改成功",param.get("elevatorTypeId"));
    }

    @Override
    public Map<String, Object> updateFlag(Map<String, Object> param) {

        Map<String, Object> result = new HashMap<>();
        try {
            String date = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
            elevatorMapp.task(date);


            // 每次查询elevatorText表的500条数据
            List<Map<String, Object>> noFlag = elevatorMapp.findNoFlag(param);

            if(noFlag !=null && noFlag.size()>0){
                param.put("elevatorList",noFlag);
                result = this.add(param);
                if("200".equals(result.get("status").toString())){
                    for(Map<String, Object> map:noFlag){
                        elevatorMapp.updateFlagSQL(map);
                    }
                }

            }
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }finally {
            elevatorMapp.deleteTask();
        }
        return ResultUtil.returnSuccess("查询成功",result);
    }

    /**
     * 通过设备Id和外部关联码进行更新操作
     * @param param
     * @return
     */
    @Override
    public Map<String, Object> elevatorUnit(Map<String, Object> param) {

        Map<String, Object> result = new HashMap<>();
        try {
            // 获取partyId
            String partyId = param.get("partyId").toString();

            // 每次查询elevatorUnit表的500条数据
            List<Map<String, Object>> units = elevatorMapp.findElevatorUnit(partyId);
            if(units !=null && units.size()>0){
                for(Map<String, Object> unit:units){
                    String usedPartyId=null;
                    Party party = null;
                    String userUnitName = unit.get("userUnitName").toString();
                    String outsideNum =null;
                    if(unit.get("outsideNum") !=null){
                        outsideNum = unit.get("outsideNum").toString();
                    }
                    if(StringUtils.isNotBlank(userUnitName)){
                        party = partyMapp.queryByName(userUnitName);
                        if(party !=null){
                            usedPartyId = party.getId().toString();
                        }
                    }
                    Elevator elevator = null;
                    String elevatorNum = unit.get("elevatorNum").toString();
                    if(StringUtils.isNotBlank(elevatorNum)){
                         elevator = elevatorMapp.queryByElevatorNum(elevatorNum);
                    }else{
                        // 获取T号
                        elevator = elevatorMapp.queryByOutsideNum(outsideNum);

                    }
                    // 更新操作
                    if(elevator !=null){
                        Map<String,Object> map = new HashMap<>();
                        map.put("id",elevator.getId().toString());
                        map.put("maintenancePartyId",partyId);
                        map.put("usedPartyId",usedPartyId);
                        map.put("outsideNum",outsideNum);
                        map.put("createBy","已更新");
                        elevatorMapp.updateById(map);

                        // 更新unit表
                        elevatorMapp.updateUnitById(unit.get("id").toString());
                    }
                }
            }

        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return ResultUtil.returnError("修改失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("修改成功",result);
    }

    @Override
    public Map<String, Object> noownerElevatorQuery(ExtElevator elevator) {
        List<ExtElevator> list =null;
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            Page<ExtElevator> page = PageHelper.startPage(elevator.getCurrentPage(), elevator.getPageSize());
            List<ExtElevator> extElevators = elevatorMapp.noownerElevatorQuery(elevator);
            map.put("listProgramName",extElevators);
            map.put("list",extElevators);
            map.put("total",page.getTotal());

        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError("查询失败"+e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("查询成功",map);
    }

    @Override
    public Map<String, Object> noownerElevatorUpdate(Map<String, Object> param) {
        Map<String,Object> map = new HashMap<String,Object>();
        try{
            if(param !=null && param.size()>0){
                //查询维保单位名称
                String maintenancePartyName =null;
                String maintenancePartyId = null;
                String usedPartyId = null;
                if(param.get("maintenanceId")!= null){
                    maintenancePartyId = param.get("maintenanceId").toString();
                    Party maintenanceParty= partyMapp.infoById(maintenancePartyId);
                    maintenancePartyName = maintenanceParty.getPartyName();
                }

                //查询使用单位名称
                String usedPartyName = null;
                if(param.get("usedPartyId") != null ){
                    usedPartyId = param.get("usedPartyId").toString();
                    Party usedParty= partyMapp.infoById(usedPartyId);
                    usedPartyName = usedParty.getPartyName();
                }

                if(param.get("ids") !=null){
                    List<String> ids = Arrays.asList(param.get("ids").toString().split(","));
                    for (String id : ids) {
                        Map<String,Object> maps = new HashMap<>();
                        maps.put("id",id);
                        maps.put("maintenancePartyId",maintenancePartyId);
                        maps.put("usedPartyId",usedPartyId);
                        maps.put("maintenancePartyName",maintenancePartyName);
                        maps.put("usedPartyName",usedPartyName);
                        elevatorMapp.noownerElevatorUpdate(maps);
                    }
                }else{
                    return ResultUtil.returnSuccess("修改错误请勾选您要修改的值",null);
                }

            }
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",map);
    }

    @Override
    @Transactional
    public Map<String, Object> elevatorLedger(MultipartFile file, String partyId, String partyName) {
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            List<List<Object>> list = ExcelUtil.getListByExcel(file.getInputStream(), file.getOriginalFilename());
            if(StringUtils.isEmpty(partyId)){
                throw new Exception("您已经离线，请刷新后重新导入");
            }
            if(StringUtils.isEmpty(partyName)){
                throw new Exception("您的公司名称为空，您联系管理员");
            }
            //获取导入的信息做处理
            if (list != null && list.size() > 0) {
                // 存储设备编号Id
                Map<String,Long> elevaormaps = new HashMap<>();
                // 存储外部关联码
                Map<String,Long> outsidemaps = new HashMap<>();
                // 查询有主电梯
                Map<String,Long> hasElevatorNums = new HashMap<>();
                Map<String,Long> hasOutsideNums = new HashMap<>();

                List<Map<String, Object>> hasmainList = elevatorMapp.hasmainElevator(partyId);
                for (Map<String, Object> hasmap : hasmainList) {
                    if (hasmap.get("elevatorNum") != null) {
                        String elevatorNum = hasmap.get("elevatorNum").toString();
                        if (StringUtils.isNotBlank(elevatorNum)) {
                            hasElevatorNums.put(elevatorNum,Long.valueOf(hasmap.get("id").toString()));
                        }
                    }
                    if (hasmap.get("outsideNum") != null) {
                        String outsideNum = hasmap.get("outsideNum").toString();
                        if (StringUtils.isNotBlank(outsideNum)) {
                            hasOutsideNums.put(outsideNum,Long.valueOf(hasmap.get("id").toString()));
                        }
                    }
                }


                // 查询无主电梯
                List<Map<String, Object>> nomainList = elevatorMapp.nomainElevator();
                for (Map<String, Object> nomap : nomainList) {
                    if(nomap.get("elevatorNum") !=null){
                        String elevatorNum = nomap.get("elevatorNum").toString();
                        if (StringUtils.isNotBlank(elevatorNum)) {
                            elevaormaps.put(elevatorNum, Long.valueOf(nomap.get("id").toString()));
                        }
                    }
                    if (nomap.get("outsideNum") != null) {
                        String outsideNum = nomap.get("outsideNum").toString();
                        if (StringUtils.isNotBlank(outsideNum)) {
                            outsidemaps.put(outsideNum, Long.valueOf(nomap.get("id").toString()));
                        }
                    }
                }


                // 存储使用单位信息
                Map<String, Long> usednameList = new HashMap<>();
                // 查询所有使用单位信息
                List<Party> partyList = partyMapp.queryByTypeList("2");
                for (Party party : partyList) {
                    usednameList.put(party.getPartyName(), party.getId());
                }

                List<Elevator> elevatorList = new ArrayList<Elevator>();
                for (int i = 0; i < list.size(); i++) {
                    List listObject = list.get(i);
                    if (listObject != null) {
                        Elevator elevator = new Elevator();
                        // 注册代码
                        if (listObject.get(0).toString() != null) {
                            elevator.setElevatorNum(listObject.get(0).toString().trim());
                        }
                        // 外部关联码
                        if (listObject.get(1) != null) {
                            elevator.setOutsideNum(listObject.get(1).toString().trim());
                        }
                        //使用单位
                        if (listObject.get(2) != null) {
                            String usedName = listObject.get(2).toString().trim();
                            elevator.setUsedPartyName(usedName);

                            Long id = usednameList.get(usedName);
                            if (id != null) {
                                elevator.setUsedPartyId(id);
                            }
                        }

                        // 维保单位
                        if (StringUtils.isNotBlank(partyId)) {
                            elevator.setMaintenancePartyId(Long.valueOf(partyId));
                        }
                        if (StringUtils.isNotBlank(partyName)) {
                            elevator.setMaintenancePartyName(partyName);
                        }
                        elevatorList.add(elevator);
                    }
                }

                //查出哪些电梯台账不在对应的台账表中
                List<Elevator> elevatorOtherList = new ArrayList<Elevator>();
                List<Elevator> elavatorExistenceList = new ArrayList<>();

                if (elevatorList != null && elevatorList.size() > 0) {

                    for (Elevator elevator : elevatorList) {
                        Long id = null;
                        if (StringUtils.isNotBlank(elevator.getElevatorNum())) {
                            // 判断是否是有主电梯
                            Long hasId = hasElevatorNums.get(elevator.getElevatorNum());
                            if (hasId != null) {
                                elevator.setId(hasId);
                                elavatorExistenceList.add(elevator);
                                continue;
                            } else {
                                id = elevaormaps.get(elevator.getElevatorNum());
                            }

                            if (id != null) {
                                elevator.setId(id);
                                elavatorExistenceList.add(elevator);
                                continue;
                            }
                        }

                        if (id == null && StringUtils.isNotBlank(elevator.getOutsideNum())) {
                            // 判断是否是有主电梯
                            Long hasId = hasOutsideNums.get(elevator.getOutsideNum());
                            if (hasId != null) {
                                elevator.setId(hasId);
                                elavatorExistenceList.add(elevator);
                                continue;
                            } else {
                                id = outsidemaps.get(elevator.getOutsideNum());
                            }

                            if (id == null) {
                                elevatorOtherList.add(elevator);
                            } else {
                                elevator.setId(id);
                                elavatorExistenceList.add(elevator);
                            }
                        } else {
                            elevatorOtherList.add(elevator);
                        }
                    }
                }

                // 处理为空的数据，进行数据保存
                if (elevatorOtherList != null) {
                    for (Elevator ele : elevatorOtherList) {
                        //添加表单
                        ElevatorLose elevatorLose = new ElevatorLose();
                        elevatorLose.setOutsideNum(ele.getOutsideNum());
                        elevatorLose.setElevatorNum(ele.getElevatorNum());
                        elevatorLose.setMaintenancePartyName(partyName);
                        elevatorLose.setUsedPartyName(ele.getUsedPartyName());
                        elevatorLoseMapp.insert(elevatorLose);
                    }
                }

                //修改维保单位id和使用单位id
                if (elavatorExistenceList != null) {
                    for (Elevator elevatorExis : elavatorExistenceList) {
                        elevatorMapp.updateMainPartyIdAndPartyId(elevatorExis);
                    }
                }
            } else {
                throw new Exception("模板Excel里暂无数据，请填写数据再次导入");
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error("上传电梯失败：" + e.getMessage(), e);
            return ResultUtil.returnError(e.getMessage(), null);
        }
        return ResultUtil.returnSuccess("成功", map);
    }

    @Override
    @Transactional
    public Map<String, Object> elevatorTypeLedger(MultipartFile file, String partyId, String partyName) {

        Map<String,Object> map = new HashMap<String,Object>();
        try {
            List<List<Object>> list = ExcelUtil.getListByExcel(file.getInputStream(), file.getOriginalFilename());
            if(StringUtils.isEmpty(partyId)){
                throw new Exception("您已经离线，请刷新后重新导入");
            }
            if(StringUtils.isEmpty(partyName)){
                throw new Exception("您的公司名称为空，您联系管理员");
            }
            //获取导入的信息做处理
            if (list != null && list.size() > 0) {
                //单位下的所有电梯
                List<ExtElevator> elevators = elevatorMapp.queryElevatorByMain(partyId);
                // 查询有主电梯
                List<String> hasElevatorNums = new ArrayList<>();
                List<String> hasOutsideNums = new ArrayList<>();
                for (ExtElevator extElevator : elevators) {
                    if (extElevator.getElevatorNum() != null) {
                        String elevatorNum = extElevator.getElevatorNum().toString();
                        if (StringUtils.isNotBlank(elevatorNum)) {
                            hasElevatorNums.add(elevatorNum);
                        }
                    }
                    if (extElevator.getOutsideNum() != null) {
                        String outsideNum = extElevator.getOutsideNum().toString();
                        if (StringUtils.isNotBlank(outsideNum)) {
                            hasOutsideNums.add(outsideNum);
                        }
                    }
                }
                // 查询所有使用单位电梯类型信息
                List<ElevatorType> elevatorTypelist = elevatorMapp.queryElevatorType();
                Map<String,Long> elevatorTypeNameList = new HashMap<>();
                for (ElevatorType elevatorType : elevatorTypelist) {
                    elevatorTypeNameList.put(elevatorType.getTypeName(),elevatorType.getId());
                }
                List<Elevator> elevatorList = new ArrayList<Elevator>();
                for (int i = 0; i < list.size(); i++) {
                    List listObject = list.get(i);
                    if (listObject != null) {
                        Elevator elevator = new Elevator();
                        // 注册代码
                        if (listObject.get(0).toString() != null) {
                            elevator.setElevatorNum(listObject.get(0).toString().trim());
                        }
                        // 外部关联码
                        if (listObject.get(1) != null) {
                            elevator.setOutsideNum(listObject.get(1).toString().trim());
                        }
                        //电梯类型
                        if (listObject.get(2) != null) {
                            String elevatorType = listObject.get(2).toString().trim();
                            elevator.setElevatorTypeName(elevatorType);
                            Long elevatorTypeId = elevatorTypeNameList.get(elevatorType);
                            if (elevatorTypeId != null) {
                                elevator.setElevatorTypeId(elevatorTypeId);
                            }
                        }
                        // 维保单位
                        if (StringUtils.isNotBlank(partyId)) {
                            elevator.setMaintenancePartyId(Long.valueOf(partyId));
                        }
                        if (StringUtils.isNotBlank(partyName)) {
                            elevator.setMaintenancePartyName(partyName);
                        }
                        elevatorList.add(elevator);
                    }
                }
                //查出哪些电梯台账不在对应的台账表中
                List<Elevator> elavatorExistenceList = new ArrayList<>();//存在的
                if (elevatorList != null && elevatorList.size() > 0) {
                    for (Elevator elevator : elevatorList) {
                        if (StringUtils.isNotBlank(elevator.getElevatorNum())) {
                            if (!hasElevatorNums.contains(elevator.getElevatorNum())) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotBlank(elevator.getOutsideNum())) {
                            if(!hasOutsideNums.contains(elevator.getOutsideNum())){
                                continue;
                            }
                        }
                        elavatorExistenceList.add(elevator);
                    }
                }
                //修改电梯类型
                for (Elevator elevator : elavatorExistenceList) {
                    elevatorMapp.banchUpdateElevatoeType(elevator);
                }
            } else {
                throw new Exception("模板Excel里暂无数据，请填写数据再次导入");
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            logger.error("上传电梯失败：" + e.getMessage(), e);
            return ResultUtil.returnError(e.getMessage(), null);
        }
        return ResultUtil.returnSuccess("成功", map);
    }

    /**
     * 根据设备编号来查询
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> publicUserElevator(String id) {
        ExtElevator elevator = null;
        try {
            elevator = elevatorMapp.publicUserElevator(id);
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",elevator);
    }

    /**
     * 查询未确认的工单
     * @param param
     * @return
     */
    @Override
    public Map<String, Object> unconfirmedMaintenance(Map<String, Object> param) {
        Map<String, Object> map = new HashMap<>();
        try {
            int currentPage = (int) param.get("currentPage");
            int pageSize = (int) param.get("pageSize");
            Page<Map<String, Object>> page = PageHelper.startPage(currentPage, pageSize);
            List<UnconfigMaintedVo> mapList = elevatorMapp.unconfirmedMaintenance(param);

            if (mapList != null && mapList.size() > 0) {
                // 获取单位下的电梯
                Map<String, UnconfigMaintedVo> eleUnitMap = new HashMap<>();
                List<UnconfigMaintedVo> eleUnits = elevatorMapp.findEleByUnit(param);
                for (UnconfigMaintedVo maintedVo : eleUnits) {
                    eleUnitMap.put(maintedVo.getElevatorNum(), maintedVo);
                }
                for (UnconfigMaintedVo vo : mapList) {
                    UnconfigMaintedVo unconfigVo = eleUnitMap.get(vo.getElevatorNum());
                    if (unconfigVo != null) {
                        vo.setOutsideNum(unconfigVo.getOutsideNum());
                        vo.setUsedPartyId(unconfigVo.getUsedPartyId());
                        vo.setSafeUserId(unconfigVo.getSafeUserId());
                        vo.setPartyName(unconfigVo.getPartyName());
                    }
                }

                // 查询所有使用单位电梯安全管理员的注册时间
                Map<String, String> usermap = new HashMap<>();
                List<Map<String, Object>> userDates = sysUserMapp.querySafeUserCreateDate();
                for (Map<String, Object> date : userDates) {
                    usermap.put(date.get("userId").toString(), date.get("createDate").toString());
                }
                for (UnconfigMaintedVo checkDate : mapList) {

                    if (checkDate.getUsedPartyId() != null) {
                        if (checkDate.getSafeUserId() != null && StringUtils.isNotBlank(checkDate.getSafeUserId().toString())) {
                            //已经关联了，还想走后门
                            String createDate = usermap.get(checkDate.getSafeUserId().toString());
                            if (createDate != null) {
                                // 安全管理员的创建时间
                                Date date = DateUtils.parseDate(createDate, "yyyyMMddHHmmss");
                                // 维保作业开始时间
                                Date parseDate = DateUtils.parseDate(checkDate.
                                                getMaintenanceStartDate(),
                                        "yyyy-MM-dd HH:mm:ss");
                                // 注册时间早于维保开始时间，跳出
                                if (date.compareTo(parseDate) < 0) {
                                    checkDate.setFlag("5");
                                    checkDate.setMessage("请通知使用单位安全管理员在手机端上确认");
                                }
                            }
                        }
                    }
                }
            }
            map.put("list", mapList);
            map.put("total", page.getTotal());
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(), null);
        }
        return ResultUtil.returnSuccess("成功", map);
    }

    /**
     *  未维保单发送通知
     * @param param
     * @return
     */
    @Override
    @Transactional
    public Map<String, Object> sendNoticeUnconfirmed(List<Map<String, Object>> param) {
        Map<String, Object> map = new HashMap<>();
        try {
            if (param != null && param.size() > 0) {
                List<Map<String, Object>> successDatas = new ArrayList<>();

                // 查询已经发送成功的电梯，将不在进行操作
                for (Map<String, Object> sendResultMap : param) {
                    String elevatorNum = sendResultMap.get("elevatorNum").toString();
                    Map<String, Object> retrunmaps = elevatorMapp.findConfirmed(elevatorNum);

                    if (retrunmaps != null) {
                        if ("1".equals(retrunmaps.get("message").toString()) || "2".equals(retrunmaps.get("message").toString())) {
                            continue;
                        } else {
                            elevatorMapp.deleteConfirmed(retrunmaps.get("id").toString());
                        }
                    }
                    String message = "2";
                    String flag = "success";
                    // 判断电梯是否关联使用单位
                    Elevator elevator = elevatorMapp.queryByElevatorNum(elevatorNum);
                    if (StringUtils.isNotBlank(elevatorNum)) {
                        if (elevator.getUsedPartyId() == null) {
                            message = "4";
                            flag = "error";
                        }else{
                            sendResultMap.put("usedPartyId",elevator.getUsedPartyId());
                        }
                    }
                    if ("success".equals(flag)) {
                        if (elevator.getSafeUserId() == null) {
                            message = "3";
                            flag = "error";
                        } else {
                            sendResultMap.put("safeUserId", elevator.getSafeUserId());
                        }
                    }

                    // 将成功的数据进行保存
                    if ("success".equals(flag)) {
                        successDatas.add(sendResultMap);
                    }
                    sendResultMap.put("message", message);
                    sendResultMap.put("createDate", new Date());
                    elevatorMapp.insertUnconfirm(sendResultMap);
                }
            } else {
                return ResultUtil.returnError("请选择您要发送通知的数据", null);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(), null);
        }
        return ResultUtil.returnSuccess("成功", map);
    }

    /**
     * 使用单位查询未确认维保工单的信息
     * @param param
     * @return
     */
    @Override
    public Map<String, Object> queryNeedconfirmedMaintenance(Map<String, Object> param) {
        Map<String,Object> map = new HashMap<>();
        try {
            int currentPage = (int) param.get("currentPage");
            int pageSize = (int) param.get("pageSize");
            Page<Map<String, Object>> page = PageHelper.startPage(currentPage, pageSize);
            List<Map<String, Object>> mapList = elevatorMapp.needconfirmedMaintenance(param);
            map.put("list",mapList);
            map.put("total",page.getTotal());
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(),null);
        }
        return ResultUtil.returnSuccess("成功",map);
    }
    /**
     * 确认未确认工单
     * @param param
     * @return
     */
    @Override
    public Map<String, Object> sureUnconfirmed(Map<String, Object> param) {
        Map<String, Object> map = new HashMap<>();
        try {
            if (param != null && param.size() > 0) {
                // 修改维保工单
                List<Map<String, Object>> sendList = (List<Map<String, Object>>) param.get("sendList");
                // 电梯安全管理员
                String userId = param.get("userId").toString();
                SystemUser systemUser = sysUserMapp.queryById(userId);
                // 当前时间
                String formatDate = DateUtils.formatDate(new Date(),
                        "yyyyMMddHHmmss");

                String tableName = "";

                for (Map<String, Object> objectMap : sendList) {
                    String workType = objectMap.get("workType").toString();
                    String elevatorNum = objectMap.get("elevatorNum").toString();
                    switch (workType) {
                        case "1":
                            tableName = "traction_half_mon";
                            // 曳引驱动电梯
                            break;
                        case "2":
                            tableName = "debris_half_mon";
                            break;
                        case "3":
                            tableName = "escalator_half_mon";
                            break;
                        case "4":
                            tableName = "hydpress_half_mon";
                            break;
                    }
                    int i = tractionMapp.updateNullConfirmd(tableName,
                            elevatorNum, systemUser.getUserName(), formatDate);
                    if (i > 0) {
                        elevatorMapp.updateSuccess(elevatorNum);
                    }
                }
            } else {
                return ResultUtil.returnError("请选择您要确认的数据", null);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.getMessage(), null);
        }
        return ResultUtil.returnSuccess("成功",map);
    }


    /**
     * 定时获取修改outSideNumber
     */
    @Override
    public void findTest() {
        String date = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
        // 获取update_flag为空的
        List<Elevator> findList = elevatorMapp.queryElevatorFlag();
        if (findList != null && findList.size() > 0) {
            for (Elevator elevator : findList) {
                String elevatorNum = elevator.getElevatorNum();
                if (StringUtils.isNotBlank(elevatorNum) && ! "NULL".equals(elevatorNum) ) {
                    try {
                        List<Elevator> nums = elevatorMapp.findElevatorList(elevatorNum);
                        if (nums != null && nums.size() > 0) {
                            // 修改
                            for (Elevator ele : nums) {
                                elevatorMapp.updateOutSideNum(String.valueOf(ele.getId()),
                                        elevator.getOutsideNum());
                            }
                        } else {
                            // 新增
                            elevatorMapp.addElevator(elevator);

                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                elevatorMapp.updateOriginal(elevator.getId(),date);
            }
        }
    }

    @Override
    public Map<String, Object> getLatLngByLevel(Map<String, Object> param) {
        List<Map<String,Object>> maps = new ArrayList<>();

        List<Map> mapList = new ArrayList<>();
        try {
            maps = elevatorMapp.getLatLngByLevel(param);

            String image = "assets/images/ok.png";

            if (maps != null && maps.size() > 0) {
                for (Map map : maps) {

                    if(map.get("placeType") !=null &&
                            StringUtils.isNotBlank(map.get("placeType").toString()) &&
                            "重点场所".equals(map.get("placeType").toString()) ){
                        image = "assets/images/nom.png";
                    }
                    Map<String, Object> resultOptions = new HashMap<>();
                    Map<String, Object> options = new HashMap<>();


                    // 经纬度
                    Map<String, Object> lngmap = new HashMap<>();
                    if (map.get("lng") == null ||
                            StringUtils.isBlank(map.get("lng").toString())) {
                        continue;
                    }

                    if (map.get("lat") == null ||
                            StringUtils.isBlank(map.get("lat").toString())) {
                        continue;
                    }

                    lngmap.put("lng", map.get("lng").toString());
                    lngmap.put("lat", map.get("lat").toString());
                    resultOptions.put("point", lngmap);

                    Map<String, Object> anchAndSize = new HashMap<>();
                    anchAndSize.put("imageUrl", image);


                    // 封装options数据
                    Map<String, Object> anchormap = new HashMap<>();
                    anchormap.put("height", "30");
                    anchormap.put("width", "10");
                    anchAndSize.put("anchor", anchormap);

                    // size
                    Map<String, Object> sizemap = new HashMap<>();
                    sizemap.put("height", "30");
                    sizemap.put("width", "20");
                    anchAndSize.put("size", sizemap);
                    // 封装最后数据
                    options.put("icon", anchAndSize);

                    String elevatorNum = "";
                    if (map.get("elevatorNum") != null &&
                            StringUtils.isNotBlank(map.get("elevatorNum").toString())) {
                        elevatorNum = map.get("elevatorNum").toString();
                    }
                    String elevatorPlace = "";
                    if (map.get("elevatorPlace") != null &&
                            StringUtils.isNotBlank(map.get("elevatorPlace").toString())) {
                        elevatorPlace = map.get("elevatorPlace").toString();
                    }

                    String typeName = "";
                    if (map.get("typeName") != null &&
                            StringUtils.isNotBlank(map.get("typeName").toString())) {
                        typeName = map.get("typeName").toString();
                    }

                    options.put("title", elevatorNum + " " + elevatorPlace + " " + typeName);
                    // 封装数据
                    resultOptions.put("options", options);

                    mapList.add(resultOptions);

                }
            }
        }catch (Exception e){
            logger.error(e.getMessage());
            return ResultUtil.returnError(e.toString(),null);
        }
        return ResultUtil.returnSuccess("成功",mapList);
    }


}
